VERSION 5.00
Begin VB.Form frmMemoryEditor 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "memory editor"
   ClientHeight    =   4695
   ClientLeft      =   150
   ClientTop       =   540
   ClientWidth     =   10950
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmMemoryEditor.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   ScaleHeight     =   4695
   ScaleWidth      =   10950
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "memory"
      Height          =   4485
      Left            =   90
      TabIndex        =   5
      Top             =   120
      Width           =   10755
      Begin VB.CommandButton Command4 
         Caption         =   "load state"
         Height          =   405
         Left            =   3480
         TabIndex        =   13
         Top             =   3960
         Width           =   1575
      End
      Begin VB.CommandButton Command3 
         Caption         =   "save state"
         Height          =   405
         Left            =   1800
         TabIndex        =   12
         Top             =   3960
         Width           =   1575
      End
      Begin VB.Frame Frame3 
         Caption         =   "bookmarks"
         Height          =   3705
         Left            =   7440
         TabIndex        =   10
         Top             =   180
         Width           =   3165
         Begin VB.ListBox lstBookmarks 
            Height          =   3315
            IntegralHeight  =   0   'False
            Left            =   120
            TabIndex        =   11
            Top             =   270
            Width           =   2925
         End
      End
      Begin VB.CommandButton Command2 
         Caption         =   "toggle pause"
         Height          =   405
         Left            =   120
         TabIndex        =   3
         Top             =   3960
         Width           =   1575
      End
      Begin VB.CommandButton Command1 
         Caption         =   "value search"
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   405
         Left            =   5160
         TabIndex        =   4
         Top             =   3960
         Width           =   1575
      End
      Begin VB.Timer Timer1 
         Interval        =   1
         Left            =   3330
         Top             =   3660
      End
      Begin VB.Frame Frame2 
         Caption         =   "edit value"
         Height          =   675
         Left            =   120
         TabIndex        =   9
         Top             =   3210
         Width           =   7215
         Begin VB.TextBox Text2 
            Height          =   285
            Left            =   1170
            TabIndex        =   2
            Text            =   "$00"
            Top             =   270
            Width           =   645
         End
         Begin VB.TextBox Text1 
            Height          =   285
            Left            =   120
            TabIndex        =   1
            Text            =   "$0000"
            Top             =   270
            Width           =   945
         End
      End
      Begin VB.PictureBox Picture2 
         BackColor       =   &H000000FF&
         BorderStyle     =   0  'None
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2880
         Left            =   120
         ScaleHeight     =   2880
         ScaleWidth      =   7215
         TabIndex        =   6
         TabStop         =   0   'False
         Top             =   270
         Width           =   7215
         Begin VB.VScrollBar VScroll1 
            Height          =   1125
            LargeChange     =   256
            Left            =   5790
            Max             =   7936
            SmallChange     =   16
            TabIndex        =   0
            Top             =   300
            Width           =   255
         End
         Begin VB.PictureBox Picture1 
            BackColor       =   &H00000000&
            BorderStyle     =   0  'None
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00400000&
            Height          =   1890
            Left            =   360
            ScaleHeight     =   1890
            ScaleWidth      =   4680
            TabIndex        =   7
            TabStop         =   0   'False
            Top             =   390
            Width           =   4680
            Begin VB.Label Label1 
               AutoSize        =   -1  'True
               BackStyle       =   0  'Transparent
               Caption         =   "$0001 - 00 FF A1 DE 47 34 42 DE    FE DE 41 0E E0 41 CC CE"
               BeginProperty Font 
                  Name            =   "Terminal"
                  Size            =   9
                  Charset         =   255
                  Weight          =   400
                  Underline       =   0   'False
                  Italic          =   0   'False
                  Strikethrough   =   0   'False
               EndProperty
               ForeColor       =   &H00FFFFFF&
               Height          =   180
               Index           =   0
               Left            =   120
               TabIndex        =   8
               Top             =   60
               Width           =   6960
            End
         End
      End
   End
End
Attribute VB_Name = "frmMemoryEditor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub RenderHexLines(f As Label, addy As Long) 'outputs the text of the hex viewer line
  f.Caption = "$" & fixaddress$(Hex(addy + 49152)) & " - " & fixvalue$(Hex(cartRam(addy))) & " " & fixvalue$(Hex(cartRam(addy + 1))) & " " & fixvalue$(Hex(cartRam(addy + 2))) & " " & fixvalue$(Hex(cartRam(addy + 3))) & " " & fixvalue$(Hex(cartRam(addy + 4))) & " " & fixvalue$(Hex(cartRam(addy + 5))) & " " & fixvalue$(Hex(cartRam(addy + 6))) & " " & fixvalue$(Hex(cartRam(addy + 7))) & "    " & fixvalue$(Hex(cartRam(addy + 8))) & " " & fixvalue$(Hex(cartRam(addy + 9))) & " " & fixvalue$(Hex(cartRam(addy + 10))) & " " & fixvalue$(Hex(cartRam(addy + 11))) & " " & fixvalue$(Hex(cartRam(addy + 12))) & " " & fixvalue$(Hex(cartRam(addy + 13))) & " " & fixvalue$(Hex(cartRam(addy + 14))) & " " & fixvalue$(Hex(cartRam(addy + 15)))
End Sub

Private Sub Command1_Click()
  Call frmValueSearch.Show 'open value searching window
End Sub

Private Sub Command2_Click()
  Pausing = Not Pausing 'toggle pausing
End Sub

Private Sub Command3_Click()

  Dim a As Integer

  a = StateSlot
  StateSlot = 10

  Call StateSave

  StateSlot = a

End Sub

Private Sub Command4_Click()

  Dim a As Integer

  a = StateSlot
  StateSlot = 10

  Call StateLoad

  StateSlot = a

End Sub


Private Sub Form_Load()

  On Error Resume Next

  Dim a As Integer

  For a% = 0 To 15 'cycles through number of lines to show
    Call Load(Label1(a%)) 'loads label
    Label1(a%).left = 0 'sets left position
    Label1(a%).top = a% * Label1(a%).Height 'sets top position
    Label1(a%).Visible = True 'makes visible
  Next a%

  Call VScroll1_Change 'update labels

  Picture1.Width = Label1(1).Width 'set background width
  Picture1.Height = Label1(1).Height * 16& 'set background height

  Picture1.top = 0 'position box in larger box
  Picture1.left = 0 'position box in larger box

  VScroll1.left = Picture1.left + Picture1.Width 'set scrollbar left
  VScroll1.top = Picture1.top 'set scrollbar top
  VScroll1.Height = Picture1.Height 'set scrollbar height

  Picture2.Width = Picture1.Width + VScroll1.Width 'set hex viewer width
  Picture2.Height = Picture1.Height 'set hex viewer heit

  Frame1.left = Me.ScaleWidth / 2 - Frame1.Width / 2 'center frame horizontally
  Frame1.top = Me.ScaleHeight / 2 - Frame1.Height / 2 'center frame vertically

  Call BookmarksLoad

  MemoryEditorOpen = True

End Sub

Private Sub Form_Unload(Cancel As Integer)

  MemoryEditorOpen = False

End Sub


Private Sub lstBookmarks_DblClick()

  Dim a As Long, b As Long

  VScroll1.value = 0 'go to beginning

  Call VScroll1_Change 'update

  b& = CLng("&H" & left$(Mid$(lstBookmarks.Text, 2), 4)) - 49152 'get bookmark addy

  For a = 0 To VScroll1.Max Step 16 'sort through ram by 16 at a time
    VScroll1.value = a 'assign value
    If a + 256 >= b& Then 'check if near the value
      Call VScroll1_Change 'update the memory viewer
      Exit For 'stop sorting
    End If
  Next a
  
End Sub

Private Sub lstBookmarks_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)

  If Button = 2 Then 'checks for right click
    Call PopupMenu(frmSMS.mnuBookmarks) 'pops up menu on main window
  End If

End Sub


Private Sub Text1_KeyPress(KeyAscii As Integer)
  Call Text2_KeyPress(KeyAscii%)
End Sub


Private Sub Text2_KeyPress(KeyAscii As Integer)

  On Error Resume Next

  If KeyAscii = vbKeyReturn Then 'checks for enter key
    cartRam(CLng("&H" & Replace(Text1.Text, "$", "")) - 49152) = CLng("&H" & Replace(Text2.Text, "$", "")) 'replace value
  End If

End Sub


Private Sub Timer1_Timer()

  If Pausing = False And Command2.Caption <> "pause" Then Command2.Caption = "pause"
  If Pausing = True And Command2.Caption <> "unpause" Then Command2.Caption = "unpause"

  Call VScroll1_Change

End Sub
Public Sub VScroll1_Change()

  'render all the text in the lines properly
  Call RenderHexLines(Label1(0), CLng(VScroll1.value))
  Call RenderHexLines(Label1(1), CLng(VScroll1.value) + 16&)
  Call RenderHexLines(Label1(2), CLng(VScroll1.value) + 16& + 16&)
  Call RenderHexLines(Label1(3), CLng(VScroll1.value) + 16& + 16& + 16&)
  Call RenderHexLines(Label1(4), CLng(VScroll1.value) + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(5), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(6), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(7), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(8), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(9), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(10), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(11), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(12), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(13), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(14), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)
  Call RenderHexLines(Label1(15), CLng(VScroll1.value) + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16& + 16&)

End Sub
